package services;

import java.util.List;
import model.Manufacturer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import dao.IManufacturerDAO;
import dao.ManufacturerDAO;
import dao.ProductDAO;

@Service("manufacturerServices")
public class ManufacturerServices implements IManufacturerDAO {

	@Autowired
	ManufacturerDAO manufacturerDAO;
	@Autowired
	ProductDAO productDAO;

	public void addManuFacturer(final String u_id, final String name,
			final String description, final String address, final String tel,
			final String website) {
		manufacturerDAO.addManuFacturer(u_id, name, description, address, tel,
				website);
	}

	@Override
	public Manufacturer getManufacturerById(int id) {
		return manufacturerDAO.getManufacturerById(id);
	}

	@Override
	public List<String> getNameManufacturerMatched(String query) {
		return manufacturerDAO.getNameManufacturerMatched(query);
	}

	@Override
	public List<Manufacturer> getAllManufacturer() {
		return manufacturerDAO.getAllManufacturer();
	}

	@Override
	public List<Manufacturer> getManuFactureByUId(String u_id) {
		return manufacturerDAO.getManuFactureByUId(u_id);
	}

	@Override
	public void deleteManufacturer(String id) {
		productDAO.deleteProductByMID(Integer.parseInt(id));
		manufacturerDAO.deleteManufacturer(id);
	}

	@Override
	public void deleteManufacturerByUID(int id) {
		for (Manufacturer manufacturer : manufacturerDAO.getManuFactureByUId(String.valueOf(id))) {
			productDAO.deleteProductByMID(Integer.parseInt(manufacturer.getId()));
		}
		manufacturerDAO.deleteManufacturerByUID(id);
	}

	@Override
	public void updateManufacturer(String name, String description,
			String address, String tel, String website, String id) {
		manufacturerDAO.updateManufacturer(name, description, address, tel,
				website, id);
	}

	@Override
	public List<String> getIdManufacturerViaName(String name) {
	return manufacturerDAO.getIdManufacturerViaName(name);
	}

}
